<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<html>
<head>
<title>修改权限</title>
<!-- layui -->
<link rel="stylesheet"
	href="${pageContext.request.contextPath }/layui/css/layui.css">
<link rel="stylesheet" type="text/css" href="/layer/layer.css" />
<script src="/layer/jquery-3.6.0.min.js"></script>
<script src="/layer/layer.js"></script>
<script src="${pageContext.request.contextPath }/layui/layui.js"></script>
<!-- layui -->

</head>

<body>
	<fieldset class="layui-elem-field">
		<legend> 修改用户权限</legend>
		<div class="layui-field-box">
			<div class="layui-form"></div>
		</div>
	</fieldset>
	<form id="formId" style="width: 1000px; padding-top: 20px"
		class="layui-form" action="/updateUserMenu" method="post">
		<div class="layui-form-item">
			<label class="layui-form-label">员工编号</label>
			<div class="layui-input-block">
				<input type="text" name="comployeeNo" readonly
					value="${comployee.comployeeNo}" required lay-verify="required"
					placeholder="请输入内容" autocomplete="off" class="layui-input">
			</div>
		</div>
		<div class="layui-form-item">
			<label class="layui-form-label">用户名</label>
			<div class="layui-input-block">
				<input type="text" name="comployeeName"
					value="${comployee.comployeeName}" readonly required
					lay-verify="required" placeholder="请输入内容" autocomplete="off"
					class="layui-input">
			</div>
		</div>

		<div class="layui-form-item">
			<label class="layui-form-label">权限</label>
			<div class="layui-input-block">
				<c:forEach items="${menus}" var="menu">
					<input type="checkbox" name="like[${menu.url}]"
						value="${menu.name}" title="${menu.name}"
						<c:if test="${mymenus.contains(menu.name)}">CHECKED="checked"</c:if>>
				</c:forEach>
			</div>
		</div>


		<div class="layui-form-item">
			<div class="layui-input-block">
				<button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
				<button type="button" onclick="window.history.back();"
					class="layui-btn layui-btn-primary">返回上一级</button>
			</div>
		</div>

	</form>

	<script>
		var $;
		layui.use([ 'form', 'laydate', 'jquery' ], function() {
			var form = layui.form;
			var laydate = layui.laydate;
			$ = layui.jquery;

			//监听提交
			form.on('submit(formDemo)', function(data) {
				console.log(data.field);
				//Ajax提交
				$.ajax({
					url : "/updateUserMenu",
					context : document.body,
					type : 'post',
					data : JSON.stringify(data.field),
					contentType : 'application/json',
					success : function(result) {
						if (result == 'error') {
							layer.msg('修改失败', {
								time : 1000, //X s后自动关闭
							});
						} else {
							layer.msg('修改成功! 即将跳转上一页...', {
								time : 1000, //2s后自动关闭
							});
							setTimeout(function() {
								window.location.href = result;
							}, 1000);
						}
					}
				});

				return false;
			});

		});
	</script>

	<!-- 111 -->

</body>

</html>
